package com.prompt;

import com.prompt.utils.TimeUtil;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AlarmActivity extends Activity {

	private static final String TAG = "AlarmActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_alarm);

		setBt();
	}

    @Override 
    protected void onResume() { 
        Log.e(TAG, "onResume"); 
        super.onResume(); 
    } 

	private void setBt(){
		
		 
		 Button btEnd =(Button)findViewById(R.id.bt_alarm_end); 
		 btEnd.setOnClickListener(new EndListener());   
		 
//		 Button btLazy =(Button)findViewById(R.id.bt_alarm_lazy); 
//		 btLazy.setOnClickListener(new LazyListener());  
	}

	private void stopAlarm(){
		Effecter.getInstance().stopVoice();
		this.finish();
		GlobalState.getInstance().setIsALarm(false);
		
		setTodayFinish();
	}

	private void setTodayFinish(){
		String today = TimeUtil.getTodayStr();
		GlobalState.getInstance().addEnd(today);
		
		SharedPreferences dateState = getSharedPreferences("dateState", 0); 
        Editor setEdit = null;
        setEdit = dateState.edit();
    	setEdit.putString(today,"1");  
    	setEdit.commit();
	}
	
	 class EndListener implements OnClickListener{
		public void onClick(View v) {   
			stopAlarm(); 
		}
	 }

	 class LazyListener implements OnClickListener{
		public void onClick(View v) {   
			 stopAlarm();
		}
	 }
}
